from flask_admin import Admin

from poker_bot.admin_panel.app import db
from poker_bot.admin_panel.app.constants import locales_folder, media_path
from poker_bot.admin_panel.app.views import (
    AccountModelView,
    AdminUserBaseModelview,
    DepositModelView,
    DiscountModelView,
    IndexView,
    MyFileAdmin,
    PaymentDetailsModelView,
    ReviewModelView,
    UserModelView,
    WithdrawModelView,
)
from poker_bot.database.models import (
    Account,
    AdminUser,
    Deposit,
    Discount,
    PaymentDetails,
    Review,
    User,
    Withdraw,
)


def init_admin_panel(app):
    admin = Admin(
        app,
        name="Admin Dashboard",
        base_template="myadmin3/my_master.html",
        template_mode="bootstrap4",
        index_view=IndexView(url="/"),
    )
    admin.add_view(
        UserModelView(
            User,
            db.session,
            name="Пользователи",
            menu_icon_type="fas",
            menu_icon_value="fa-user",
            endpoint="users",
        )
    )
    admin.add_view(
        AccountModelView(
            Account,
            db.session,
            name="Аккаунты",
            menu_icon_type="fas",
            menu_icon_value="fa-user-circle",
            endpoint="accouns",
        )
    )
    admin.add_view(
        DepositModelView(
            Deposit,
            db.session,
            name="Депозиты",
            menu_icon_type="fas",
            menu_icon_value="fa-file-invoice-dollar",
            endpoint="deposits",
        )
    )
    admin.add_view(
        WithdrawModelView(
            Withdraw,
            db.session,
            name="Запросы на вывод",
            menu_icon_type="fas",
            menu_icon_value="fa-money-check-alt",
            endpoint="withdrawals",
        )
    )
    admin.add_view(
        DiscountModelView(
            Discount,
            db.session,
            name="Акции",
            menu_icon_type="fas",
            menu_icon_value="fa-gifts",
            endpoint="discounts",
        )
    )
    admin.add_view(
        PaymentDetailsModelView(
            model=PaymentDetails,
            session=db.session,
            name="Методы оплаты",
            menu_icon_type="fas",
            menu_icon_value="fa-credit-card",
            endpoint="payment_details",
        )
    )
    admin.add_view(
        ReviewModelView(
            model=Review,
            session=db.session,
            name="Отзывы",
            menu_icon_type="fas",
            menu_icon_value="fa-comment",
            endpoint="reviews",
        )
    )
    admin.add_view(
        AdminUserBaseModelview(
            AdminUser,
            db.session,
            name="Администраторы",
            menu_icon_type="fas",
            menu_icon_value="fa-users",
            endpoint="admin-user",
        )
    )
    admin.add_view(
        MyFileAdmin(
            locales_folder,
            name="Переводы",
            menu_icon_type="fas",
            menu_icon_value="fa-copy",
            endpoint="translations",
        )
    )
    admin.add_view(
        MyFileAdmin(
            media_path,
            name="Загруженные файлы",
            menu_icon_type="fas",
            menu_icon_value="fa-copy",
        )
    )
